//
// Created by xu on 2024/11/12.
//
#include <libavformat/avformat.h>


int find_best_stream(const char *path) {
    AVFormatContext *p_fmt_ctx = NULL;
    int v_idx = -1;
    const AVCodec *p_codec = NULL;
    int ret;

    ret = avformat_open_input(&p_fmt_ctx, path, NULL, NULL);
    if (ret < 0) {
        printf("avformat_open_input() failed!\n");
        return -1;
    }

    v_idx = av_find_best_stream(p_fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &p_codec, 0);
    if (v_idx >= 0) {
        AVStream *v_stream = p_fmt_ctx->streams[v_idx];
        AVCodecParameters *v_codec_par = v_stream->codecpar;
        av_log(NULL, AV_LOG_INFO, "分辨率：%dx%d\n", v_codec_par->width, v_codec_par->height);
        av_log(NULL, AV_LOG_INFO, "编解码器：%s\n", p_codec->name);
    }
    avformat_close_input(&p_fmt_ctx);
    return 0;
}

int main(int argc, char *argv[]) {
    int ret;
    ret = find_best_stream("C:\\Users\\xu\\Downloads\\123.mp4");
    return ret;
}